
<template>
  <div class="main-container">
    <div class="filtrate-bar">
      <div class="title-box">
        <div class="icon-box">
          <span class="wk wk-my-task icon" />
        </div>
        <span class="text">外仓报告 {{ fromDate + '~' + thruDate }}</span>
      </div>
    </div>

    <div class="table-content">
      <div class="handle-bar">
        <!-- <a-button class="export-btn">导出</a-button> -->
      </div>
      <a-table :scroll="{ y: 300 }" :columns="fieldList" :data-source="tableList" bordered :pagination="false">
        <span slot="estimatedDivAvailableRateFormat" slot-scope="text, record">
          {{ record.estimatedDivAvailableRate + '%' }}
        </span>
        <span slot="estimatedFreezeRate" slot-scope="text, record">
          {{ record.estimatedFreezeRate + '%' }}
        </span>
        <span slot="estimatedRefrigerateRate" slot-scope="text, record">
          {{ record.estimatedRefrigerateRate + '%' }}
        </span>
        <span slot="estimatedConstantRate" slot-scope="text, record">
          {{ record.estimatedConstantRate + '%' }}
        </span>
        <span slot="estimatedNormalRate" slot-scope="text, record">
          {{ record.estimatedNormalRate + '%' }}
        </span>
      </a-table>
    </div>

    <div class="analysis">
      <a-row :span="24">
        <a-col :span="24"
          ><div class="analysis-content">
            <div id="analysisoutside1" />
            <div class="tips">
              <!-- <div style="padding-left: 5px; border-left: 30px solid red">未达标部分</div> -->
              <!-- <div style="padding-left: 5px; border-left: 30px solid yellow">
                在售/空余 距离达标值 比例 （小于 100%）
              </div>
              <div style="padding-left: 5px; border-left: 30px solid #52c41a">在售/空余 比例</div> -->
            </div>
          </div>
        </a-col>
      </a-row>

      <!-- <a-row :span="24">
        <a-col :span="24"
          ><div class="analysis-content">
            <div id="analysisoutside2" /></div
        ></a-col>
      </a-row> -->
    </div>

    <!-- <div class="analysis">
      <a-row :span="24">
        <a-col :span="12"
          ><div class="analysis-content">
            <div id="analysisAll5" /></div
        ></a-col>
        <a-col :span="12"
          ><div class="analysis-content">
            <div id="analysisAll6" /></div
        ></a-col>
      </a-row>
    </div> -->
  </div>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
export default {
  /** 客户总量分析 */
  name: 'OutsideReport',
  data() {
    return {
      loading: false,
      fromDate: '',
      thruDate: '',
      chartAnalysis1: null,
      chartAnalysis3: null,
      // chartAnalysis5: null,
      // chartAnalysis6: null,
      analysis1Option: null,
      analysis3Option: null,
      // analysis5Option: null,
      // analysis6Option: null,

      url: {
        getSalesDataTotalAnalysis: '/online/api/getOutsideWmsReport',
        businessListByProductCategory: '/online/api/businessListByProductCategory',
        exportXlsUrl: '/online/api/export/exportXlsGraphReport',
      },
      postParams: {}, // 筛选参数
      dataIndex: null,
      list: [],
      axisList: [],
      fieldList: [
        {
          title: '部门',
          align: 'center',
          dataIndex: 'warehouseName',
          key: 'warehouseName',
          width: 80,
        },
        {
          title: '销售数据',
          align: 'center',
          children: [
            {
              title: '冷冻',
              align: 'center',
              dataIndex: 'estimatedFreeze',
              key: 'estimatedFreeze',
              width: 90,
            },
            {
              title: '冷藏',
              align: 'center',
              dataIndex: 'estimatedRefrigerate',
              key: 'estimatedRefrigerate',
              width: 90,
            },
            {
              title: '恒温',
              align: 'center',
              dataIndex: 'estimatedConstant',
              key: 'estimatedConstant',
              width: 90,
            },
            {
              title: '常温',
              align: 'center',
              dataIndex: 'estimatedNormal',
              key: 'estimatedNormal',
              width: 90,
            },
            {
              title: '合计',
              align: 'center',
              dataIndex: 'estimatedTotal',
              key: 'estimatedTotal',
              width: 90,
            },
          ],
        },
      ],
      tableList: [],
    }
  },
  computed: {
    // 列表请求参数
    listPostParams() {
      const params = { ...this.postParams }

      if (this.dataIndex !== undefined && this.dataIndex !== null) {
        const dataItem = this.axisList[this.dataIndex]
        delete params.type
        params.startTime = dataItem.type
        params.endTime = dataItem.type
      }

      return params
    },
  },
  mounted() {
    this.initAxis()
  },
  methods: {
    /**
     * 搜索点击
     */
    searchClick(params) {
      this.postParams = params
      this.getDataList()
      this.getRecordList()
    },
    /**
     * 图表数据   待完善
     */
    getDataList() {
      this.chartAnalysis1.setOption(this.analysis1Option, true)
      //this.chartAnalysis2.setOption(this.analysis2Option, true)
      this.chartAnalysis3.setOption(this.analysis3Option, true)
      // this.chartAnalysis5.setOption(this.analysis5Option, true)
      // this.chartAnalysis6.setOption(this.analysis6Option, true)
    },
    /**
     * 获取相关列表
     */
    getRecordList(dataIndex) {
      this.dataIndex = dataIndex
      this.list = []
      this.loading = true
      biCustomerTotalListAPI(this.listPostParams)
        .then((res) => {
          this.loading = false
          const data = res.result || {}
          this.list = data.list || []
          this.getSummariesData(data.total)
        })
        .catch(() => {
          this.loading = false
        })
    },

    /** 图表 */
    initAxis() {
      this.chartAnalysis1 = this.echarts.init(document.getElementById('analysisoutside1'))
      // this.chartAnalysis3 = this.echarts.init(document.getElementById('analysisoutside2'))
      // this.chartAnalysis5 = this.echarts.init(document.getElementById('analysisAll5'))
      // this.chartAnalysis6 = this.echarts.init(document.getElementById('analysisAll6'))

      this.analysis1Option = {
        title: {
          text: '外仓销售报告',
        },
        dataZoom: [
          {
            // 控制图表左右滑动
            width: '15',
            type: 'slider',
            show: false, //flase直接隐藏图形
            xAxisIndex: [0],
            left: 33, //滚动条靠左侧的百分比
            bottom: 40,
            height: 20, //组件高度
            start: 0, //滚动条的起始位置
            showDataShadow: false, //是否显示数据阴影
            showDetail: false, //是否显示想洗数值信息
            end: 100, //滚动条的截止位置（按比例分割你的柱状图x轴长度）
          },
          {
            type: 'inside',
            show: true,
            xAxisIndex: [0],
            start: 0, //滚动条的起始位置
            end: 0.25, //滚动条的截止位置（按比例分割你的柱状图x轴长度）
          },
        ],
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            // 坐标轴指示器，坐标轴触发有效
            type: 'shadow', // 默认为直线，可选为：'line' | 'shadow'
          },
          // formatter: function (params, ticket, callback) {
          //   console.log(params)
          //   var htmlStr = ''
          //   for (var i = 0; i < params.length; i++) {
          //     var param = params[i]
          //     var xName = param.name
          //     var seriesName = param.seriesName
          //     var value = param.value ? param.value + '%' : '-'
          //     var color = param.color
          //     if (i === 0) {
          //       htmlStr += xName + '<br/>'
          //     }
          //     htmlStr += '<div>'
          //     htmlStr +=
          //       '<span style="margin-right:5px;display:inline-block;width:10px;height:10px;border-radius:5px;background-color:' +
          //       color +
          //       ';"></span>'
          //     htmlStr += seriesName + '：' + value
          //     htmlStr += '<div/>'
          //   }
          //   return htmlStr
          // },
        },
        legend: {
          data: [
            '冷冻销售',
            '冷藏销售',
            '恒温销售',
            '常温销售',
          ],
        },
        grid: {
          left: '2%',
          right: '2%',
          bottom: '3%',
          containLabel: true,
        },
        xAxis: [
          {
            axisLabel: {
              interval: 0,
              // rotate: 30,
            },
            type: 'category',
            data: [],
          },
        ],
        yAxis: [
          {
            type: 'value',
            axisLabel: {
              // formatter: '{value}%',
            },
          },
        ],
        series: [
          {
            name: '冷冻销售',
            type: 'bar',
            color: '#0000FF',
            barWidth: '8%',
            label: {
              show: true,
              position: 'top',
              // offset: [0, -10],
              // formatter: '{@[0]}%',
            },
            emphasis: {
              focus: 'series',
            },
            data: [],
          },
          {
            name: '冷藏销售',
            type: 'bar',
            color: '#FFFF00',
            barWidth: '8%',
            label: {
              show: true,
              position: 'top',
              // offset: [0, -10],
              // formatter: '{@[0]}%',
            },
            emphasis: {
              focus: 'series',
            },
            data: [],
          },
          {
            name: '恒温销售',
            type: 'bar',
            color: '#00980d',
            barWidth: '8%',
            label: {
              show: true,
              position: 'top',
              // offset: [0, -10],
              // formatter: '{@[0]}%',
            },
            emphasis: {
              focus: 'series',
            },
            data: [],
          },
          {
            name: '常温销售',
            type: 'bar',
            color: '#800080',
            barWidth: '8%',
            label: {
              show: true,
              position: 'top',
              // offset: [0, -10],
              // formatter: '{@[0]}%',
            },
            emphasis: {
              focus: 'series',
            },
            data: [],
          },
        ],
      }

  
      const param = {}

      getAction(this.url.getSalesDataTotalAnalysis, param).then((res) => {
        this.tableList = res.result.workMap.salesDataListByWarehouse
        this.fromDate = res.result.workMap.fromDate
        this.thruDate = res.result.workMap.thruDate

        let buList = []
        let estimatedFreezeList = []
        let estimatedRefrigerateList = []
        let estimatedConstantList = []
        let estimatedNormalList = []

        let customerProduct = []

      
        res.result.workMap.salesDataListByWarehouse.forEach((element) => {
          buList.push(element.warehouseName)
          estimatedFreezeList.push(element.estimatedFreeze)
          estimatedRefrigerateList.push(element.estimatedRefrigerate)
          estimatedConstantList.push(element.estimatedConstant)
          estimatedNormalList.push(element.estimatedNormal)
        })
        

        this.analysis1Option.xAxis[0].data = buList
        this.analysis1Option.series[0].data = estimatedFreezeList
        this.analysis1Option.series[1].data = estimatedRefrigerateList
        this.analysis1Option.series[2].data = estimatedConstantList
        this.analysis1Option.series[3].data = estimatedNormalList

        

        this.$nextTick(() => {
          this.getDataList()
        })
      })
    },

    /**
     * 导出点击
     */
    exportClick() {
      this.requestExportInfo(biCustomerTotalListExportAPI, this.listPostParams)
    },
  },
}
</script>


<style lang="less" scoped>
/deep/ .ant-table-thead > tr > th,
.ant-table-tbody > tr > td {
  padding: 10px 4px;
}
.main-container {
  border: 1px solid #e6e6e6;
  border-radius: 2px;
  background-color: white;
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  position: relative;
}

.filtrate-bar {
  background-color: white;
  padding: 15px 20px 5px 20px;
  margin-right: 15px;
  line-height: 34px;
  .icon-box {
    width: 34px;
    height: 34px;
    text-align: center;
    line-height: 34px;
    color: #168a40;
    background-color: #dfe8ff;
    border-radius: 50%;
    margin-right: 10px;
    float: left;
  }
  .text {
    font-size: 17px;
    font-weight: 700;
  }
}

.content-title {
  padding: 10px 20px 5px;
  font-size: 16px;
  color: #333;
}
.analysis {
  margin-top: 10px;
  .analysis-content {
    padding: 8px 10px;
    .tips {
      padding-left: 8%;
      font-size: 12px;
      div {
        margin-bottom: 8px;
      }
    }
    #analysisoutside1 {
      margin: 0 auto;
      width: 95%;
      height: 400px;
    }
    #analysisoutside2 {
      margin: 0 auto;
      width: 95%;
      height: 400px;
    }

    #analysisoutside5 {
      margin: 0 auto;
      width: 95%;
      height: 400px;
    }
    #analysisoutside6 {
      margin: 0 auto;
      width: 95%;
      height: 400px;
    }
  }
}

.axis-content {
  padding: 20px 10% 40px;
  position: relative;
  .axismain,
  #summaryAll1 {
    margin: 0 auto;
    width: 100%;
    height: 400px;
  }
}

.table-content {
  padding: 0 30px 20px 30px;
}

.export-button {
  float: right;
  margin-right: 22px;
}

// 导出操作bug
.handle-bar {
  margin-bottom: 8px;
  text-align: right;
}

.search-box {
  padding-right: 15px;
}

.radio-box {
  padding: 0 20px;
  margin-bottom: 15px;
  /deep/ .el-radio__label {
    color: #99a9bf !important;
  }
}

.static {
  padding: 0 20px;
  margin-bottom: 10px;
  .text {
    font-size: 13px;
    color: #99a9bf;
    display: inline-block;
  }
  .text:not(:last-child) {
    margin-right: 15px;
  }
}
/deep/ .ant-table-wrapper {
  border: 1px solid #ebeef5;
}
/deep/ .ant-table-placeholder {
  display: none;
}
</style>

